package com.viknix.threadpool.manager.common.result;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author: Dongqi
 * @Date: 2021/10/22 15:26
 * @Version 1.0
 * @Description: ResultModel
 */
@Data
public class ResultModel<T> implements Serializable {

    private static final long serialVersionUID = 3630086750578851769L;

    public static final String SUCCESS_CODE = "200";

    public String code;
    public String message;
    public T data;

    public ResultModel(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultModel(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public boolean isSuccess() {
        return SUCCESS_CODE.equals(code);
    }

    public static ResultModel success(Object object) {
        return new ResultModel("200", "请求成功", object);
    }

    public static ResultModel success() {
        return new ResultModel("200", "请求成功");
    }

    public static ResultModel success(String code, String msg) {
        return new ResultModel(code, msg);
    }

    public static ResultModel fail(String code, String message) {
        return new ResultModel(code, message, (Object)null);
    }

    public static ResultModel fail(String message) {
        return new ResultModel("500", message, (Object)null);
    }
}
